<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var flag = setInterval(func,1000);
    let count = 0;
    function func(){
        if(count<5)
        {
            alert("反复执行");
            count++;
        }
        else
        {
            clearInterval(flag);
            alert("执行完毕");
        }
    }




    // var flag = setTimeout("func()",3000);
    // function func(){
    //     alert("指定时间结束后，只执行一次");
    // }
//取消定时任务
    // function stop(){
    //     clearTimeout(flag);
    // }
</script>
</html>